<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<script src="../script/mui.min.js"></script>
		<script src="../script/db.js" type="text/javascript" charset="utf-8"></script>
		<script src="../script/template.js" type="text/javascript" charset="utf-8"></script>
		<link href="../css/mui.min.css" rel="stylesheet" />
		<style type="text/css">
			.more {
				display: none;
			}
		</style>
	</head>

	<body>
		<ul class="mui-table-view" id="list">
		</ul>
		<script type="text/html" id="listTem">
			{{each}}
			<li class="mui-table-view-cell">
				<a class="mui-navigate-right" data-id="{{$value.id}}">
					<span class="mui-ellipsis-2" style="width: 85%;">{{$value.stem}}</span>
				</a>
			</li>
			{{/each}}
			<li class="mui-table-view-cell mui-text-center more" id="more">数据可能较多，请输入更精确的关键词</li>
		</script>
		<script type="text/javascript">
			apiready = function() {
				var data = api.pageParam;
				var keyword = data.text;
				var cid = localStorage.getItem('cid');
				var func = function(db) {
					var sql = 'SELECT id,stem FROM question where stem like \'%' + keyword + '%\' order by id asc  limit 0,20';
					db.selectSql({
						name: 'data',
						sql: sql
					}, function(ret, err) {
						if (ret.status) {
							var html = template('listTem', ret.data);
							document.getElementById("list").innerHTML = html;
							var more = '';
							if (ret.data.length == 20) {
								document.getElementById("more").style.display = "block";
							}
						} else {
							api.toast({
								msg: err.msg
							});
						}
					});
				}
				APP.openQDb(func);
				mui('#list').on('tap', 'a', function() {
					var id = this.getAttribute('data-id');
					var data = {
						id: id
					}
					api.openWin({
						name: 'quesiton',
						url: 'question.html',
						pageParam: data
					});
				});
			}
		</script>
	</body>

</html>